home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
games
/
rosa3
/
src
/
rosa.c
next >
Wrap
Text File
|
1998-02-11
|
50KB
|
2,228 lines
#include "rosa.h"
#include "zfunc.h"
#include "graph.h"
void main();
static void PreGame(void);
static void GameMain(void);
static void Term(void);
static char MyInit(void);
static void MazeDisp(void);
static void BlockDraw(short i,short j);
static void TileDraw(short i,short j);
static void SpInit(void);
static char GameMainLoop(void);
static void MyChrMove(void);
static void DispSprite(void);
static void Gate(void);
static char Demo(void);
static char MazeLoad(void);
static char CreateEnemy(short i , short j,char Type);
static char Bgm(unsigned char i);
static char BgmRead(void);
static void Se(unsigned char i);
static char SeRead(void);
static void EnemyMain(void);
static char EnemyInit(void);
static char GateInit(void);
static char CreateGate(short i, short j);
static void EnemyOikake1(_Enemy *Enemy);
static void EnemyOikake2(_Enemy *Enemy);
static void WaitVDisp(void);
static void StageClear(void);
static void MyChrDead(void);
static void GameOver(int Y);
static void ScoreDisp(void);
static void DispStage(short Y);
static void TargetDisp(void);
static void AllClear(void);
static _Sprite *sp;
static char GameStatus;
static unsigned char GameStage;
static unsigned char *MazePtr;
static unsigned int MazeCnt;
static _Enemy *Start =(_Enemy *)NULL
,*End =(_Enemy *)NULL;
static _Gate *GateStart =(_Gate *)NULL
,*GateEnd =(_Gate *)NULL;
static unsigned char EnemyCnt;
static char BgmFlag;
static unsigned char *BgmPtr[32];
static int BgmSize[32];
static unsigned char *SePtr[32];
static int SeSize[32];
static short CursorY;
static char PushFlag;
static unsigned int Score;
static unsigned int HiScore=10000;
static char MyLeft;
static char EnemyDownFlag;
static unsigned char ContinueCnt=0;
static unsigned int ContinueMazeCnt;
static unsigned int ExtendEvery = 0;
static unsigned int AnimeCnt = 0;
static char PushAFlag;
static int EnemyDownRate;
static short TargetX;
static short TargetY;
static short TargetTimer;
static short GateCloseCnt;
static char PcmFlag;
static int StageHiScore[50];
static int StageScore;
static void
AllClear()
{
int Loop;
int i;
int LoopI;
unsigned short Ptn;
unsigned char Cnt;
BGTEXTCL(1,0x0100);
Bgm(5);
for (Loop=0;Loop<4;Loop++) {
Cnt=0;
for (i=274;i> -80;i-=1) {
SpInit();
sp = &Sprite[0];
for (LoopI=0;LoopI<4;LoopI++) {
sp->X = 56+(LoopI*16);
sp->Y = 32;
sp->Ptn = 0x0590+LoopI;
sp->Pri = 3;
sp++;
}
sp->X = 120;
sp->Y = 32;
sp->Ptn = 0x0594;
sp->Pri = 3;
sp++;
for (LoopI=0;LoopI<4;LoopI++) {
sp->X = 136+(LoopI*16);
sp->Y = 32;
sp->Ptn = 0x0590+LoopI;
sp->Pri = 3;
sp++;
}
sp->X = 216;
sp->Y = 32;
sp->Ptn = 0x0595;
sp->Pri = 3;
sp++;
for (LoopI=0;LoopI<6;LoopI++) {
sp->X = 96+(LoopI*16);
sp->Y = 96;
sp->Ptn = 0x05b3+LoopI;
sp->Pri = 3;
sp++;
}
Cnt++;
if (Cnt ==28) Cnt=0;
Ptn=0x0170+(Cnt/4);
sp->X = i+20;
sp->Y = 128+(Loop*16)-16;
sp->Ptn = Ptn-0x10;
sp->Pri = 3;
sp++;
sp->X = i+20;
sp->Y = 128+(Loop*16);
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
Ptn=0x0667+(Cnt/7);
sp->X = i+60;
sp->Y = 128+(Loop*16);
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
Ptn=0x0767+(Cnt/7);
sp->X = i+76;
sp->Y = 128+(Loop*16);
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
for (LoopI=0;LoopI<6;LoopI++) {
sp->X = 96+(LoopI*16);
sp->Y = 208;
sp->Ptn = 0x05B9+LoopI;
sp->Pri = 3;
sp++;
}
ScoreDisp();
DispSprite();
}
Cnt=0;
for (i=-80;i<274;i++) {
SpInit();
sp = &Sprite[0];
for (LoopI=0;LoopI<4;LoopI++) {
sp->X = 56+(LoopI*16);
sp->Y = 32;
sp->Ptn = 0x0590+LoopI;
sp->Pri = 3;
sp++;
}
sp->X = 120;
sp->Y = 32;
sp->Ptn = 0x0594;
sp->Pri = 3;
sp++;
for (LoopI=0;LoopI<4;LoopI++) {
sp->X = 136+(LoopI*16);
sp->Y = 32;
sp->Ptn = 0x0590+LoopI;
sp->Pri = 3;
sp++;
}
sp->X = 216;
sp->Y = 32;
sp->Ptn = 0x0595;
sp->Pri = 3;
sp++;
for (LoopI=0;LoopI<6;LoopI++) {
sp->X = 96+(LoopI*16);
sp->Y = 96;
sp->Ptn = 0x05b3+LoopI;
sp->Pri = 3;
sp++;
}
Cnt++;
if (Cnt ==28) Cnt=0;
Ptn=0x0157+(Cnt/4);
sp->X = i+56;
sp->Y = 128+(Loop*16)-16;
sp->Ptn = Ptn-0x10;
sp->Pri = 3;
sp++;
sp->X = i+56;
sp->Y = 128+(Loop*16);
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
Ptn=0x066B+(Cnt/7);
sp->X = i;
sp->Y = 128+(Loop*16);
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
Ptn=0x076B+(Cnt/7);
sp->X = i+16;
sp->Y = 128+(Loop*16);
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
for (LoopI=0;LoopI<6;LoopI++) {
sp->X = 96+(LoopI*16);
sp->Y = 208;
sp->Ptn = 0x05B9+LoopI;
sp->Pri = 3;
sp++;
}
ScoreDisp();
DispSprite();
}
}
FadeOut(10);
for (i=0;i<400;i++) {
WaitVDisp();
}
}
void
TargetDisp(void)
{
if (TargetTimer > 400) return;
TargetTimer++;
if (My->X == TargetX && My->Y == TargetY) {
Score += (((GameStage-1)&7)+1)*3000;
StageScore += (((GameStage-1)&7)+1)*3000;
TargetTimer = 1000;
Se(5);
PcmFlag = -1;
}
if (TargetTimer > 300) {
if (!(TargetTimer&1)) return;
}
sp->X = TargetX;
sp->Y = TargetY;
sp->Ptn = 0x08A0+((GameStage-1)&7);
if (((GameStage-1)&7)==7) sp->Ptn += 0x0100;
sp->Pri = 3;
sp++;
}
void
main()
{
int i;
char *OpmName = "OPM";
int hOpm;
hOpm = OPEN(OpmName,0x001); /* ôKôûé╚ÅφÆôâ`âFâbâNé┼é╖ */
if (hOpm < 0) {
printf("âTâEâôâhüEâhâëâCâoé¬ÅφÆôé╡é─éóé▄é╣é±üBÅIù╣é╡é▄é╖\n");
EXIT();
}
CLOSE(hOpm);
for (i=0;i<32;i++) {
BgmPtr[i] = (unsigned char *)NULL;
SePtr[i] = (unsigned char *)NULL;
}
MazePtr = (unsigned char *)NULL;
if (!MazeLoad()) Term();
if (!BgmRead()) Term();
if (!SeRead()) Term();
PreGame();
GameMain();
Term();
}
static void
PreGame(void)
{
int i;
B_SUPER(0);
CRTMOD(10);
G_CLR_ON();
B_CUROFF();
SP_OFF();
SpInit();
DispSprite();
BGCTRLST(1,1,1);
BGSCRLST(1,0,0);
BGTEXTCL(1,0x0100);
SP_ON();
Bgm(0);
for (i=0;i<30;i++) WaitVDisp(); /* ë╣ÉFÉ▌ÆΦé▄é┼é╠ï≤âïü[âv */
}
static void
GameMain(void)
{
FILE *FilePtr;
int i;
for (i=0;i<50;i++) {
StageHiScore[i]=0;
}
/* Score Load */
FilePtr = fopen("Hisc.dat","rb");
if (FilePtr != NULL) {
fread(&HiScore,sizeof(int),1,FilePtr);
for (i=0;i<50;i++) {
fread(&StageHiScore[i],sizeof(int),1,FilePtr);
}
}
if (!MyInit()) Term();
if (!EnemyInit()) Term();
if (!GateInit()) Term();
GameStatus = 0;
BgmFlag = 0;
while ( !(GameMainLoop()) );
}
static void
Term(void)
{
_Gate *GatePtr,*GateDummy;
_Enemy *Enemy,*EnemyDummy;
int i;
int DriveType;
FILE *FilePtr;
BgmStop();
/* Protect Check. */
DriveType = DRVCTRL(0,0);
DriveType &= 0x08;
/* Score Save */
if (!DriveType) { /* No Protect */
FilePtr = fopen("Hisc.dat","wb");
if (FilePtr != NULL) {
fwrite(&HiScore,sizeof(int),1,FilePtr);
for (i=0;i<50;i++) {
fwrite(&StageHiScore[i],sizeof(int),1,FilePtr);
}
}
fclose (FilePtr);
}
if (MazePtr != NULL) free(MazePtr);
for (i=0;i<32;i++) {
if (BgmPtr[i] != NULL) free(BgmPtr[i]);
if (SePtr[i] != NULL) free(SePtr[i]);
}
if (My != NULL) free(My);
if (GateStart != NULL && GateEnd != NULL) {
GatePtr = GateStart->Next;
while (GatePtr->Next != NULL) {
GateDummy = GatePtr;
GatePtr->Prev->Next = GatePtr->Next;
GatePtr->Next->Prev = GatePtr->Prev;
GatePtr = GatePtr->Next;
free(GateDummy);
}
}
if (GateStart != NULL) free(GateStart);
if (GateEnd != NULL) free(GateEnd);
if (Start != NULL && End != NULL) {
Enemy = Start->Next;
while (Enemy->Next != NULL) {
EnemyDummy = Enemy;
Enemy->Prev->Next = Enemy->Next;
Enemy->Next->Prev = Enemy->Prev;
Enemy = Enemy->Next;
free(EnemyDummy);
}
}
if (Start != NULL) free(Start);
if (End != NULL) free(End);
KFLUSHIO( 0xFE );
CRTMOD(16);
G_CLR_ON();
B_CURON();
EXIT();
}
static void
SpInit(void)
{
int i;
(_Sprite *)sp = (_Sprite *)Sprite;
for (i=0;i<128;i++) {
sp->Pri = 0;
sp++;
}
}
static char
GameMainLoop(void)
{
_Gate *GatePtr,*Dummy;
_Enemy *Enemy,*EnemyDummy;
int i=0;
short Y;
if ( *(char *)0x080C == 0x02) return -1;
switch (GameStatus) {
case 0:{
SpInit();
(_Sprite *)sp = (_Sprite *)Sprite;
if (!BgmFlag) {
if (!Bgm(1)) Term();
PushAFlag = -1;
MazeCnt = 0;
CursorY = 224;
if (ContinueCnt) CursorY = 208;
/* MazeDisp(); */
BGTEXTCL(1,0x0100);
}
if (Demo()) return -1;
return 0;
}
case 1:{
PcmFlag=0;
if (!BgmFlag) {
SpInit();
(_Sprite *)sp = &Sprite[5];
TargetX = My->X;
TargetY = My->Y;
GateCloseCnt = 0;
TargetTimer = 1000;
StageScore = 0;
MyChrMove();
EnemyMain();
Gate();
ScoreDisp();
Bgm(2);
for (Y=256;Y>24;Y-=3) {
DispStage(Y);
DispSprite();
}
} else {
SpInit();
(_Sprite *)sp = &Sprite[5];
MyChrMove();
EnemyMain();
TargetDisp();
Gate();
ScoreDisp();
DispStage(24);
DispSprite();
}
BgmFlag = 1;
if (!EnemyCnt) {
GameStatus = 2;
}
if (GameStatus == 6) BgmFlag = 0;
if (*(char *)0x0800 == 0x02) GameStatus = 3;
if (*(char *)0x0804 == 0x04) {
BgmFlag = 0;
GameStatus = 6;
}
return 0;
}
case 2: {
StageClear();
GatePtr = GateStart->Next;
while (GatePtr->Next != NULL) {
Dummy = GatePtr;
GatePtr->Prev->Next = GatePtr->Next;
GatePtr->Next->Prev = GatePtr->Prev;
GatePtr = GatePtr->Next;
free(Dummy);
}
GameStage++;
GameStatus = 1;
BgmFlag = 0;
ContinueMazeCnt = MazeCnt;
MazeDisp();
return 0;
}
case 3: {
if (*(char *)0x0800 != 0x02) GameStatus = 4;
return 0;
}
case 4: {
if (*(char *)0x0800 == 0x02) GameStatus = 5;
return 0;
}
case 5: {
if (*(char *)0x0800 != 0x02) GameStatus = 1;
return 0;
}
case 6: {
if (!BgmFlag) if (!Bgm(3)) Term();
BgmFlag = 1;
MyChrDead();
MyLeft--;
if (MyLeft < 0) GameStatus = 7;
My->X = My->InitX;
My->Y = My->InitY;
if (GameStatus != 7) {
Enemy = Start->Next;
while (Enemy->Next != NULL) {
Enemy->X = Enemy->InitX;
Enemy->Y = Enemy->InitY;
Enemy->Houkou = 0;
Enemy->Cnt = 0;
Enemy->DownCnt = 0;
Enemy = Enemy->Next;
}
}
GatePtr = GateStart->Next;
while (GatePtr->Next != NULL) {
GatePtr->Status = 5;
GatePtr->OpenFlag = 0;
GatePtr = GatePtr->Next;
}
BgmFlag=0;
return 0;
}
case 7: {
for (Y=0;Y<128;Y++) {
SpInit();
(_Sprite *)sp = &Sprite[5];
GameOver(Y);
ScoreDisp();
EnemyMain();
Gate();
DispStage(24);
DispSprite();
}
i=0;
while (i<120) {
WaitVDisp();
i++;
}
GatePtr = GateStart->Next;
while (GatePtr->Next != NULL) {
Dummy = GatePtr;
GatePtr->Prev->Next = GatePtr->Next;
GatePtr->Next->Prev = GatePtr->Prev;
GatePtr = GatePtr->Next;
free(Dummy);
}
Enemy = Start->Next;
while (Enemy->Next != NULL) {
EnemyDummy = Enemy;
Enemy->Prev->Next = Enemy->Next;
Enemy->Next->Prev = Enemy->Prev;
Enemy = Enemy->Next;
free(EnemyDummy);
}
GameStatus = 0;
return 0;
}
}
return 0;
}
static void
StageClear(void)
{
unsigned short Ptn;
unsigned int i=0;
char BestDisp=0;
unsigned char LoopI=0;
unsigned int Point;
unsigned int Temp;
unsigned int DummyScore;
BestDisp = 0;
if (StageScore > StageHiScore[GameStage-1]) {
StageHiScore[GameStage-1] = StageScore;
BestDisp = 1;
}
while (i<80) {
SpInit();
(_Sprite *)sp = &Sprite[5];
DispStage(24);
/* Stage Result. */
if (BestDisp) {
if ((i%10)<5) {
for (LoopI=0;LoopI<3;LoopI++) {
sp->X = 64+(LoopI*16);
sp->Y = 128;
sp->Ptn = 0x05B0+LoopI;
sp->Pri = 3;
sp++;
}
}
}
sp->X = 64;
sp->Y = 64;
sp->Ptn = 0x04A8;
sp->Pri = 3;
sp++;
sp->X = 80;
sp->Y = 64;
sp->Ptn = 0x04A9;
sp->Pri = 3;
sp++;
sp->X = 64;
sp->Y = 96;
sp->Ptn = 0x04AA;
sp->Pri = 3;
sp++;
sp->X = 80;
sp->Y = 96;
sp->Ptn = 0x04AB;
sp->Pri = 3;
sp++;
LoopI=0;
Point = 1000000;
DummyScore = StageHiScore[GameStage-1];
while (LoopI<7) {
if (DummyScore >= Point) {
Temp = DummyScore/Point;
DummyScore -= (Temp*Point);
sp->X = 104+(LoopI*8);
sp->Y = 64;
sp->Ptn = 0x0414+Temp;
sp->Pri = 3;
sp++;
} else {
sp->X = 104+(LoopI*8);
sp->Y = 64;
sp->Ptn = 0x0414;
sp->Pri = 3;
sp++;
}
Point = Point / 10;
LoopI++;
}
LoopI=0;
Point = 1000000;
DummyScore = StageScore;
while (LoopI<7) {
if (DummyScore >= Point) {
Temp = DummyScore/Point;
DummyScore -= (Temp*Point);
sp->X = 104+(LoopI*8);
sp->Y = 96;
sp->Ptn = 0x0414+Temp;
sp->Pri = 3;
sp++;
} else {
sp->X = 104+(LoopI*8);
sp->Y = 96;
sp->Ptn = 0x0414;
sp->Pri = 3;
sp++;
}
Point = Point / 10;
LoopI++;
}
if ((i%20)<10) {
Ptn=0x0129;
} else {
Ptn=0x012A;
}
sp->X = My->X;
sp->Y = My->Y;
sp->Ptn = Ptn+0x10;
sp->Pri = 3;
sp++;
sp->X = My->X;
sp->Y = My->Y-16;
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
Gate();
ScoreDisp();
DispSprite();
i++;
}
for (i=0;i<40;i++) {
WaitVDisp();
}
}
static void
MyChrDead(void)
{
int i=0;
unsigned short Ptn;
while (i<60) {
SpInit();
(_Sprite *)sp = &Sprite[5];
DispStage(24);
if ((i%20)<10) {
Ptn=0x012B;
} else {
Ptn=0x012C;
}
sp->X = My->X;
sp->Y = My->Y;
sp->Ptn = Ptn+0x10;
sp->Pri = 3;
sp++;
sp->X = My->X;
sp->Y = My->Y-16;
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
EnemyMain();
Gate();
ScoreDisp();
DispSprite();
i++;
}
GameStatus = 1;
}
static void
ScoreDisp()
{
unsigned char i;
unsigned int Point;
unsigned int Temp;
unsigned int DummyScore;
char DummyLeft;
sp->X = 16+8;
sp->Y = 256;
sp->Ptn = 0x040A;
sp->Pri = 3;
sp++;
sp->X = 32+8;
sp->Y = 256;
sp->Ptn = 0x040B;
sp->Pri = 3;
sp++;
sp->X = 128;
sp->Y = 256;
sp->Ptn = 0x040C;
sp->Pri = 3;
sp++;
sp->X = 144;
sp->Y = 256;
sp->Ptn = 0x040D;
sp->Pri = 3;
sp++;
sp->X = 216;
sp->Y = 256;
sp->Ptn = 0x040E;
sp->Pri = 3;
sp++;
sp->X = 232;
sp->Y = 256;
sp->Ptn = 0x040F;
sp->Pri = 3;
sp++;
i=0;
Point = 1000000;
DummyScore = Score;
while (i<7) {
if (DummyScore >= Point) {
Temp = DummyScore/Point;
DummyScore -= (Temp*Point);
sp->X = 48+(i*8)+8;
sp->Y = 256;
sp->Ptn = 0x0414+Temp;
sp->Pri = 3;
sp++;
} else {
sp->X = 48+(i*8)+8;
sp->Y = 256;
sp->Ptn = 0x0414;
sp->Pri = 3;
sp++;
}
Point = Point / 10;
i++;
}
if (Score > HiScore) HiScore = Score;
while (ExtendEvery < Score) {
ExtendEvery *=2;
MyLeft++;
}
i=0;
Point = 1000000;
DummyScore = HiScore;
while (i<7) {
if (DummyScore >= Point) {
Temp = DummyScore/Point;
DummyScore -= (Temp*Point);
sp->X = 160+(i*8);
sp->Y = 256;
sp->Ptn = 0x0414+Temp;
sp->Pri = 3;
sp++;
} else {
sp->X = 160+(i*8);
sp->Y = 256;
sp->Ptn = 0x0414;
sp->Pri = 3;
sp++;
}
Point = Point / 10;
i++;
}
i=0;
Point = 10;
DummyLeft = MyLeft;
if (DummyLeft < 0) DummyLeft = 0; /*üEüEüEôKôûé╚Åêù¥*/
while (i<2) {
if (DummyLeft >= Point) {
Temp = DummyLeft/Point;
DummyLeft -= (Temp*Point);
sp->X = 248+(i*8);
sp->Y = 256;
sp->Ptn = 0x0414+Temp;
sp->Pri = 3;
sp++;
} else {
sp->X = 248+(i*8);
sp->Y = 256;
sp->Ptn = 0x0414;
sp->Pri = 3;
sp++;
}
Point = Point / 10;
i++;
}
}
static void
DispStage(short Y)
{
unsigned char i;
unsigned int Point;
unsigned int Temp;
unsigned int DummyStage;
_Sprite *Sp;
(_Sprite *)Sp = &Sprite[0];
Sp->X = Y;
Sp->Y = 18;
Sp->Ptn = 0x0583;
Sp->Pri = 3;
Sp++;
Sp->X = Y+16;
Sp->Y = 18;
Sp->Ptn = 0x0584;
Sp->Pri = 3;
Sp++;
Sp->X = Y+32;
Sp->Y = 18;
Sp->Ptn = 0x0585;
Sp->Pri = 3;
Sp++;
i=0;
Point = 10;
DummyStage = GameStage;
while (i<2) {
if (DummyStage >= Point) {
Temp = DummyStage/Point;
DummyStage -= (Temp*Point);
Sp->X = Y+48+(i*8);
Sp->Y = 18;
Sp->Ptn = 0x0414+Temp;
Sp->Pri = 3;
Sp++;
} else {
Sp->X = Y+48+(i*8);
Sp->Y = 18;
Sp->Ptn = 0x0414;
Sp->Pri = 3;
Sp++;
}
Point = Point / 10;
i++;
}
}
static unsigned char
GetKeyPort()
{
unsigned char KeyPort = *(unsigned char *)0xE9A001;
if ( KeyPort == 0xFF ) {
if ((*(unsigned char *)0x0807 & 0x10) == 0x10 ) KeyPort &= 0xFE;
if ((*(unsigned char *)0x0807 & 0x40) == 0x40 ) KeyPort &= 0xFD;
if ((*(unsigned char *)0x0807 & 0x08) == 0x08 ) KeyPort &= 0xFB;
if ((*(unsigned char *)0x0807 & 0x20) == 0x20 ) KeyPort &= 0xF7;
if ((*(unsigned char *)0x080A & 0x20) == 0x20 ) KeyPort &= 0x2F;
if ((*(unsigned char *)0x080A & 0x40) == 0x40 ) KeyPort &= 0x4F;
}
return KeyPort;
}
static char
Demo(void)
{
int i;
unsigned char KeyPort = GetKeyPort();
/* â^âCâgâïò\Ī */
for (i=0;i<4;i++) {
sp->X = 56+(i*16);
sp->Y = 32;
sp->Ptn = 0x0590+i;
sp->Pri = 3;
sp++;
}
sp->X = 120;
sp->Y = 32;
sp->Ptn = 0x0594;
sp->Pri = 3;
sp++;
for (i=0;i<4;i++) {
sp->X = 136+(i*16);
sp->Y = 32;
sp->Ptn = 0x0590+i;
sp->Pri = 3;
sp++;
}
sp->X = 216;
sp->Y = 32;
sp->Ptn = 0x0595;
sp->Pri = 3;
sp++;
/* âLâââëò\Ī */
/* Rosa */
sp->X = 104;
sp->Y = 80;
sp->Ptn = 0x0128;
sp->Pri = 3;
sp++;
sp->X = 104;
sp->Y = 96;
sp->Ptn = 0x0138;
sp->Pri = 3;
sp++;
for (i=0;i<3;i++) {
sp->X = 136+(i*16);
sp->Y = 96;
sp->Ptn = 0x0596+i;
sp->Pri = 3;
sp++;
}
/* Monster */
sp->X = 104;
sp->Y = 120;
sp->Ptn = 0x0677;
sp->Pri = 3;
sp++;
for (i=0;i<3;i++) {
sp->X = 136+(i*16);
sp->Y = 120;
sp->Ptn = 0x0599+i;
sp->Pri = 3;
sp++;
}
/* Monster */
sp->X = 104;
sp->Y = 144;
sp->Ptn = 0x0777;
sp->Pri = 3;
sp++;
for (i=0;i<3;i++) {
sp->X = 136+(i*16);
sp->Y = 144;
sp->Ptn = 0x0599+i;
sp->Pri = 3;
sp++;
}
/* Gate */
sp->X = 104;
sp->Y = 168;
sp->Ptn = 0x0203;
sp->Pri = 3;
sp++;
for (i=0;i<2;i++) {
sp->X = 136+(i*16);
sp->Y = 168;
sp->Ptn = 0x059C+i;
sp->Pri = 3;
sp++;
}
if (PushAFlag == -1) {
if ((KeyPort&0x40)!=0 && (KeyPort&0x20)!=0) PushAFlag = 0;
}
for (i=0;i<3;i++) {
sp->X = 120+(i*16);
sp->Y = 224;
sp->Ptn = 0x052d+i;
sp->Pri = 3;
sp++;
}
for (i=0;i<2;i++) {
sp->X = 120+(i*16);
sp->Y = 240;
sp->Ptn = 0x053d+i;
sp->Pri = 3;
sp++;
}
if (ContinueCnt) {
for (i=0;i<3;i++) {
sp->X = 120+(i*16);
sp->Y = 208;
sp->Ptn = 0x0580+i;
sp->Pri = 3;
sp++;
}
sp->X = 168;
sp->Y = 208;
sp->Ptn = 0x0414+ContinueCnt;
sp->Pri = 3;
sp++;
}
if (PushFlag) {
if (((KeyPort&0x01)!=0) && ((KeyPort&0x02)!=0)) PushFlag = 0;
}
if (((KeyPort & 0x01) == 0) && (!PushFlag) ) {
CursorY -= 16;
if (CursorY < 224) {
if (ContinueCnt) {
CursorY = 208;
} else {
CursorY = 240;
}
}
PushFlag = -1;
}
if (((KeyPort & 0x02) == 0) && (!PushFlag) ) {
CursorY += 16;
if (CursorY > 240 ) {
if (ContinueCnt) {
CursorY = 208;
} else {
CursorY = 224;
}
}
PushFlag = -1;
}
sp->X = 104;
sp->Y = CursorY;
sp->Ptn = 0x053F;
sp->Pri = 3;
sp++;
ScoreDisp();
DispSprite();
if (!BgmFlag) {
for (i=0;i<30;i++) {
WaitVDisp();
}
BgmFlag = 1;
}
if (CursorY == 208 || CursorY == 224) {
if (!PushAFlag) {
if (((KeyPort&0x40)==0) || ((KeyPort&0x20)==0)) {
GameStatus = 1;
/*GameStage = 1;*/
BgmFlag = 0;
MyLeft = 2;
Score = 0;
ExtendEvery = 10000;
EnemyCnt = 0;
MazeCnt = 0;
EnemyDownRate = 260;
if (CursorY == 224) {
ContinueMazeCnt = MazeCnt;
ContinueCnt = 3;
GameStage = 1;
}
if (CursorY == 208) {
MazeCnt = ContinueMazeCnt;
ContinueMazeCnt = MazeCnt;
ContinueCnt -= 1;
}
MazeDisp();
}
}
}
if (CursorY == 240) {
if (!PushAFlag) {
if (((KeyPort&0x40)==0) || ((KeyPort&0x20)==0)) {
return -1;
}
}
}
return 0;
}
static void
GameOver(int Y)
{
short i;
for (i=0;i<5;i++) {
sp->X = 104+(i*16);
sp->Y = Y;
sp->Ptn = 0x0486+i;
sp->Pri = 3;
sp++;
}
}
static void
MazeDisp(void)
{
short i,j;
char LoopFlag;
for (i=0;i<15;i++) {
for (j=0;j<15;j++) {
LoopFlag=0;
while (!LoopFlag) {
switch (MazePtr[MazeCnt]) {
case 0x21: {
AllClear(); /* All Stage Clear */
/*
Term();
*/
MazeCnt = 0;
GameStage = 1;
if (EnemyDownRate > 200) EnemyDownRate -= 20;
break;
}
case 0x30: {
TileDraw(i,j);
LoopFlag = -1;
MazeCnt++;
break;
}
case 0x31: {
BlockDraw(i,j);
LoopFlag = -1;
MazeCnt++;
break;
}
case 0x4d: {
if (!CreateEnemy(i,j,0)) {
printf("ôGâLâââëé╠âüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
Term(); /* Abort */
}
TileDraw(i,j);
LoopFlag = -1;
MazeCnt++;
break;
}
case 0x4e: {
if (!CreateEnemy(i,j,1)) {
printf("ôGâLâââëé╠âüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
Term(); /* Abort */
}
TileDraw(i,j);
LoopFlag = -1;
MazeCnt++;
break;
}
case 0x47: {
if (!CreateGate(i,j)) {
printf("âQü[âgé╠âüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
Term(); /* Abort */
}
TileDraw(i,j);
LoopFlag = -1;
MazeCnt++;
break;
}
case 0x52: {
TileDraw(i,j);
My->X = j*16+16+8;
My->Y = i*16+16+8;
My->InitX = j*16+16+8;
My->InitY = i*16+16+8;
My->Houkou = 0;
My->Cnt = 0;
LoopFlag = -1;
MazeCnt++;
break;
}
default:
if ((0x80 <= MazePtr[MazeCnt] && MazePtr[MazeCnt] <= 0x9F)
|| (0xE0 <= MazePtr[MazeCnt] && MazePtr[MazeCnt] <= 0xFE)) {
MazeCnt+=2;
} else {
MazeCnt++;
}
}
}
}
}
}
static void
BlockDraw(short i,short j)
{
short *Addr ;
(short *)Addr = 0xEBE000+128;
(short *)Addr += (i*2) * 64 + (j*2) + 1;
*(short *)Addr = 0x0204;
*(short *)(Addr+1) = 0x0206;
*(short *)(Addr+64) = 0x0205;
*(short *)(Addr+65) = 0x0207;
}
static void
TileDraw(short i,short j)
{
short *Addr ;
(short *)Addr = 0xEBE000+128;
(short *)Addr += (i*2) * 64 + (j*2) + 1;
*(short *)Addr = 0x0208;
*(short *)(Addr+1) = 0x020A;
*(short *)(Addr+64) = 0x0209;
*(short *)(Addr+65) = 0x020B;
}
static char
MyInit(void)
{
(_MyChr *)My = (_MyChr *)malloc(sizeof(_MyChr));
if (My == NULL) return 0;
return -1;
}
static void
MyChrMove()
{
unsigned short *Addr;
unsigned short Ptn;
unsigned char OldHoukou;
unsigned char KeyPort = GetKeyPort();
OldHoukou=My->Houkou;
if ( (((My->X-24) % 16) == 0)
&& ( ((My->Y-24) % 16) == 0) ) {
My->UpFlag = 0;
My->DownFlag = 0;
My->LeftFlag = 0;
My->RightFlag = 0;
My->Houkou = 0;
(unsigned short *)Addr = (unsigned short *)0xEBE002+((My->Y-24)/8)*64+((My->X-24)/8)+64;
if (*(short *)(Addr-64) > 0x0207 && *(short *)(Addr-63) > 0x0207) My->UpFlag = 1;
if (*(short *)(Addr+128) > 0x0207 && *(short *)(Addr+129)> 0x0207) My->DownFlag = 1;
if (*(short *)(Addr-1) > 0x0207 && *(short *)(Addr+63) > 0x0207) My->LeftFlag = 1;
if (*(short *)(Addr+2) > 0x0207 && *(short *)(Addr+66) > 0x0207) My->RightFlag = 1;
}
if (((My->X-8) % 16) == 0) {
if (OldHoukou > 2) {
if ( ((KeyPort & 0x01) == 0) && (My->UpFlag == 1) ) My->Houkou = 1;
if ( ((KeyPort & 0x02) == 0) && (My->DownFlag == 1) ) My->Houkou = 2;
}
}
if (((My->Y-8) % 16) == 0) {
if (OldHoukou < 3) {
if ( ((KeyPort & 0x04) == 0) && (My->LeftFlag == 1) ) My->Houkou = 3;
if ( ((KeyPort & 0x08) == 0) && (My->RightFlag == 1) ) My->Houkou = 4;
}
}
if (My->Houkou == 1 || !My->Houkou) {
if (((My->X-8) % 16) == 0) {
if ( ((KeyPort & 0x02) == 0) && (My->DownFlag == 1) ) My->Houkou = 2;
}
}
if (My->Houkou == 2 || !My->Houkou) {
if (((My->X-8) % 16) == 0) {
if ( ((KeyPort & 0x01) == 0) && (My->UpFlag == 1) ) My->Houkou = 1;
}
}
if (My->Houkou == 3 || !My->Houkou) {
if (((My->Y-8) % 16) == 0) {
if ( ((KeyPort & 0x08) == 0) && (My->RightFlag == 1) ) My->Houkou = 4;
}
}
if (My->Houkou == 4 || !My->Houkou) {
if (((My->Y-8) % 16) == 0) {
if ( ((KeyPort & 0x04) == 0) && (My->LeftFlag == 1) ) My->Houkou = 3;
}
}
if (My->Houkou == 1) My->Y--;
if (My->Houkou == 2) My->Y++;
if (My->Houkou == 3) My->X--;
if (My->Houkou == 4) My->X++;
My->Cnt++;
if (My->Cnt == 28) My->Cnt = 0;
if (My->Houkou == 1) Ptn=0x0120+(My->Cnt/4);
if (My->Houkou == 2) Ptn=0x0140+(My->Cnt/4);
if (My->Houkou == 3) Ptn=0x0160+(My->Cnt/4);
if (My->Houkou == 4) Ptn=0x0147+(My->Cnt/4);
if (!My->Houkou) Ptn=0x0127+(My->Cnt/14);
sp->X = My->X;
sp->Y = My->Y;
sp->Ptn = Ptn+0x10;
sp->Pri = 3;
sp++;
sp->X = My->X;
sp->Y = My->Y-16;
sp->Ptn = Ptn;
sp->Pri = 3;
sp++;
}
static void
DispSprite()
{
volatile char *Reg;
int i;
_Sprite *Addr;
short *PalAddr;
short Table[3] = {0x0026,0x0030,0x403e};
unsigned char SetWork;
AnimeCnt++;
if (AnimeCnt == 18) AnimeCnt=0;
SetWork = AnimeCnt / 6;
(short *)PalAddr = 0x0e82244;
(char *)Reg = 0xE88001;
while (!(*Reg & 0x10));
while ( (*Reg & 0x10));
for (i=0;i<3;i++) {
*(short *)PalAddr = Table[SetWork];
PalAddr++;
SetWork++;
if (SetWork == 3) SetWork = 0;
}
(_Sprite *)Addr = 0xEB0000;
(_Sprite *)sp = (_Sprite *)Sprite;
for (i=0;i<128;i++) {
*(_Sprite *)Addr++ = *(_Sprite *)sp++;
}
}
static void
WaitVDisp(void)
{
volatile char *Reg;
(char *)Reg = 0xE88001;
while (!(*Reg & 0x10));
while ( (*Reg & 0x10));
}
static char
MazeLoad(void)
{
FILE *FilePtr;
int Size;
FilePtr = fopen("MazeData.Dat","rt");
if (FilePtr != NULL) {
Size = filelength(fileno(FilePtr));
if (((unsigned char *)MazePtr=(unsigned char *)malloc(Size)) == NULL) {
printf("â}âbâvüEâfü[â^é╠âüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
fclose(FilePtr);
return 0;
} else {
fread(MazePtr,1,filelength(fileno(FilePtr)),FilePtr);
fclose(FilePtr);
return -1;
}
} else {
printf("â}âbâvüEâfü[â^é╠ô╟é▌ì₧é▌é╔Ä╕ösé╡é▄é╡é╜üB\n");
return 0;
}
}
static char
CreateEnemy(short i, short j,char Type)
{
_Enemy *Enemy;
if ( ((_Enemy *)Enemy=(_Enemy *)malloc(sizeof(_Enemy))) == NULL ) return 0;
Enemy->Next = Start->Next;
Enemy->Prev = Start;
Enemy->Prev->Next = Enemy;
Enemy->Next->Prev = Enemy;
Enemy->X = j*16+16+8;
Enemy->Y = i*16+16+8;
Enemy->InitX = j*16+16+8;
Enemy->InitY = i*16+16+8;
Enemy->Type = Type;
Enemy->Houkou = 0;
Enemy->Cnt = 0;
Enemy->DownCnt = 0;
EnemyCnt ++;
return -1;
}
static char
EnemyInit(void)
{
if ( ((_Enemy *)Start=(_Enemy *)malloc(sizeof(_Enemy))) == NULL ) {
printf("ôGâLâââëérésé`éqésâüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
return 0;
}
if ( ((_Enemy *)End=(_Enemy *)malloc(sizeof(_Enemy))) == NULL ) {
printf("ôGâLâââëédémécâüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
return 0;
}
Start->Prev = NULL;
Start->Next = End;
End->Prev = Start;
End->Next = NULL;
return -1;
}
static char
GateInit(void)
{
if ( ((_Gate *)GateStart=(_Gate *)malloc(sizeof(_Gate))) == NULL ) {
printf("âQü[âgérésé`éqésâüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
return 0;
}
if ( ((_Gate *)GateEnd=(_Gate *)malloc(sizeof(_Gate))) == NULL ) {
printf("âQü[âgédémécâüâéâèé╠èmò█é╔Ä╕ösé╡é▄é╡é╜\n");
return 0;
}
GateStart->Prev = NULL;
GateStart->Next = GateEnd;
GateEnd->Prev = GateStart;
GateEnd->Next = NULL;
return -1;
}
static void
EnemyMain(void)
{
_Enemy *Enemy;
EnemyDownFlag = 0;
Enemy = Start->Next;
while ( Enemy->Next != NULL ) {
if (!Enemy->DownCnt) {
if ( !Enemy->Type ) {
EnemyOikake1(Enemy);
} else {
EnemyOikake2(Enemy);
}
if ((My->X < (Enemy->X+8)) && ((My->X+8) > Enemy->X)
&& (My->Y < (Enemy->Y+8)) && ((My->Y+8) > Enemy->Y)) GameStatus = 6;
} else {
Enemy->DownCnt--;
if (!Enemy->DownCnt) {
if (!PcmFlag) {
Se(4);
PcmFlag = -1;
}
Enemy->Cnt = 0;
}
Enemy->Cnt++;
if (Enemy->Cnt < 16) {
sp->X = Enemy->X;
sp->Y = Enemy->Y;
if (!Enemy->Type) {
sp->Ptn = 0x068b+(Enemy->Cnt/4);
} else {
sp->Ptn = 0x078b+(Enemy->Cnt/4);
}
sp->Pri = 3;
sp++;
} else {
if (Enemy->DownCnt < 16) {
sp->X = Enemy->X;
sp->Y = Enemy->Y;
if (!Enemy->Type) {
sp->Ptn = 0x068b+(Enemy->DownCnt/4);
} else {
sp->Ptn = 0x078b+(Enemy->DownCnt/4);
}
sp->Pri = 3;
sp++;
} else {
if (Enemy->Cnt == 32) Enemy->Cnt = 16;
sp->X = Enemy->X;
sp->Y = Enemy->Y-8;
sp->Ptn = 0x0310+((Enemy->Cnt-16)/7);
sp->Pri = 3;
sp++;
}
}
}
Enemy = Enemy->Next;
}
}
static void
EnemyOikake1(_Enemy *Enemy)
{
char UpFlag = 0;
char DownFlag = 0;
char LeftFlag = 0;
char RightFlag = 0;
char OldHoukou = Enemy->Houkou;
char MoveCnt = 0;
short *Addr;
short Ptn=0x0677;
_Gate *Gate;
Enemy->Cnt ++;
if (Enemy->Cnt == 28) Enemy->Cnt = 0;
if (!(Enemy->Cnt%2) && (GameStatus == 1)) {
if ( (((Enemy->X-24) % 16) == 0) && ( ((Enemy->Y-24) % 16) == 0) ) {
(unsigned short *)Addr = (unsigned short *)0xEBE002+((Enemy->Y-24)/8)*64+((Enemy->X-24)/8)+64;
Enemy->Houkou = 0;
if (*(short *)(Addr-64) > 0x0207 && *(short *)(Addr-63) > 0x0207) {
UpFlag = 1;
MoveCnt++;
}
if (*(short *)(Addr+128) > 0x0207 && *(short *)(Addr+129)> 0x0207) {
DownFlag = 1;
MoveCnt++;
}
if (*(short *)(Addr-1) > 0x0207 && *(short *)(Addr+63) > 0x0207) {
LeftFlag = 1;
MoveCnt++;
}
if (*(short *)(Addr+2) > 0x0207 && *(short *)(Addr+66) > 0x0207) {
RightFlag = 1;
MoveCnt++;
}
if (MoveCnt > 1) {
if (OldHoukou == 3 || OldHoukou == 4 || !OldHoukou) {
if ((UpFlag == 1) && (My->Y < Enemy->Y)) Enemy->Houkou = 1;
if ((DownFlag == 1) && (My->Y > Enemy->Y)) Enemy->Houkou = 2;
}
if (OldHoukou == 1 || OldHoukou == 2 || !OldHoukou) {
if ((LeftFlag == 1) && (My->X < Enemy->X)) Enemy->Houkou = 3;
if ((RightFlag == 1) && (My->X > Enemy->X)) Enemy->Houkou = 4;
}
if (!Enemy->Houkou) {
if (OldHoukou == 1 && UpFlag) Enemy->Houkou = 1;
if (OldHoukou == 2 && DownFlag) Enemy->Houkou = 2;
if (OldHoukou == 3 && LeftFlag) Enemy->Houkou = 3;
if (OldHoukou == 4 && RightFlag) Enemy->Houkou = 4;
}
if (!Enemy->Houkou) {
if (OldHoukou == 1 && RightFlag) Enemy->Houkou = 4;
if (OldHoukou == 4 && DownFlag) Enemy->Houkou = 2;
if (OldHoukou == 2 && LeftFlag) Enemy->Houkou = 3;
if (OldHoukou == 3 && UpFlag) Enemy->Houkou = 1;
}
if (!Enemy->Houkou) {
if (RightFlag) Enemy->Houkou = 4;
if (!Enemy->Houkou && DownFlag) Enemy->Houkou = 2;
if (!Enemy->Houkou && LeftFlag) Enemy->Houkou = 3;
if (!Enemy->Houkou && UpFlag) Enemy->Houkou = 1;
}
} else {
if (OldHoukou == 1 || (!Enemy->Houkou && DownFlag)) Enemy->Houkou = 2;
if (OldHoukou == 2 || (!Enemy->Houkou && UpFlag)) Enemy->Houkou = 1;
if (OldHoukou == 3 || (!Enemy->Houkou && RightFlag)) Enemy->Houkou = 4;
if (OldHoukou == 4 || (!Enemy->Houkou && LeftFlag)) Enemy->Houkou = 3;
}
}
if (Enemy->Houkou == 1) Enemy->Y -= 1;
if (Enemy->Houkou == 2) Enemy->Y += 1;
if (Enemy->Houkou == 3) Enemy->X -= 1;
if (Enemy->Houkou == 4) Enemy->X += 1;
Gate = GateStart->Next;
while (Gate->Next != NULL) {
if (Gate->X == Enemy->X && Gate->Y == Enemy->Y && Gate->OpenFlag == 2) {
if (!EnemyDownFlag) {
Se(3);
EnemyDownFlag = -1;
}
Enemy->Cnt = 0;
Enemy->DownCnt = EnemyDownRate;
break;
}
Gate=Gate->Next;
}
}
if (Enemy->Houkou == 1) Ptn=0x067B;
if (Enemy->Houkou == 2) Ptn=0x0677;
if (Enemy->Houkou == 3) Ptn=0x0667;
if (Enemy->Houkou == 4) Ptn=0x066B;
sp->X = Enemy->X;
sp->Y = Enemy->Y;
sp->Ptn = Ptn+((Enemy->Cnt/7));
sp->Pri = 3;
sp++;
}
static void
EnemyOikake2(_Enemy *Enemy)
{
char UpFlag = 0;
char DownFlag = 0;
char LeftFlag = 0;
char RightFlag = 0;
char OldHoukou = Enemy->Houkou;
char MoveCnt = 0;
short *Addr;
short Ptn=0x0777;
_Gate *Gate;
Enemy->Cnt ++;
if (Enemy->Cnt == 28) Enemy->Cnt = 0;
if (!(Enemy->Cnt%2) && (GameStatus == 1)) {
if ( (((Enemy->X-8) % 16) == 0) && ( ((Enemy->Y-8) % 16) == 0) ) {
(unsigned short *)Addr = (unsigned short *)0xEBE002+((Enemy->Y-24)/8)*64+((Enemy->X-24)/8)+64;
Enemy->Houkou = 0;
if (*(short *)(Addr-64) > 0x0207 && *(short *)(Addr-63) > 0x0207) {
UpFlag = 1;
MoveCnt++;
}
if (*(short *)(Addr+128) > 0x0207 && *(short *)(Addr+129)> 0x0207) {
DownFlag = 1;
MoveCnt++;
}
if (*(short *)(Addr-1) > 0x0207 && *(short *)(Addr+63) > 0x0207) {
LeftFlag = 1;
MoveCnt++;
}
if (*(short *)(Addr+2) > 0x0207 && *(short *)(Addr+66) > 0x0207) {
RightFlag = 1;
MoveCnt++;
}
if (MoveCnt > 1) {
if (OldHoukou == 3 || OldHoukou == 4 || !OldHoukou) {
if ((UpFlag == 1) && (My->Y < Enemy->Y)) Enemy->Houkou = 1;
if ((DownFlag == 1) && (My->Y > Enemy->Y)) Enemy->Houkou = 2;
}
if (OldHoukou == 1 || OldHoukou == 2 || !OldHoukou) {
if ((LeftFlag == 1) && (My->X < Enemy->X)) Enemy->Houkou = 3;
if ((RightFlag == 1) && (My->X > Enemy->X)) Enemy->Houkou = 4;
}
if (!Enemy->Houkou) {
if (OldHoukou == 1 && UpFlag) Enemy->Houkou = 1;
if (OldHoukou == 2 && DownFlag) Enemy->Houkou = 2;
if (OldHoukou == 3 && LeftFlag) Enemy->Houkou = 3;
if (OldHoukou == 4 && RightFlag) Enemy->Houkou = 4;
}
if (!Enemy->Houkou) {
if (OldHoukou == 1 && LeftFlag) Enemy->Houkou = 3;
if (OldHoukou == 3 && DownFlag) Enemy->Houkou = 2;
if (OldHoukou == 2 && RightFlag) Enemy->Houkou = 4;
if (OldHoukou == 4 && UpFlag) Enemy->Houkou = 1;
}
if (!Enemy->Houkou) {
if (LeftFlag) Enemy->Houkou = 3;
if (!Enemy->Houkou && DownFlag) Enemy->Houkou = 2;
if (!Enemy->Houkou && RightFlag) Enemy->Houkou = 4;
if (!Enemy->Houkou && UpFlag) Enemy->Houkou = 1;
}
} else {
if (OldHoukou == 1 || (!Enemy->Houkou && DownFlag)) Enemy->Houkou = 2;
if (OldHoukou == 2 || (!Enemy->Houkou && UpFlag)) Enemy->Houkou = 1;
if (OldHoukou == 3 || (!Enemy->Houkou && RightFlag)) Enemy->Houkou = 4;
if (OldHoukou == 4 || (!Enemy->Houkou && LeftFlag)) Enemy->Houkou = 3;
}
}
if (Enemy->Houkou == 1) Enemy->Y -= 1;
if (Enemy->Houkou == 2) Enemy->Y += 1;
if (Enemy->Houkou == 3) Enemy->X -= 1;
if (Enemy->Houkou == 4) Enemy->X += 1;
Gate = GateStart->Next;
while (Gate->Next != NULL) {
if (Gate->X == Enemy->X && Gate->Y == Enemy->Y && Gate->OpenFlag == 2) {
if (!EnemyDownFlag) {
Se(3);
EnemyDownFlag = -1;
}
Enemy->Cnt = 0;
Enemy->DownCnt = EnemyDownRate;
break;
}
Gate=Gate->Next;
}
}
if (Enemy->Houkou == 1) Ptn=0x077B;
if (Enemy->Houkou == 2) Ptn=0x0777;
if (Enemy->Houkou == 3) Ptn=0x0767;
if (Enemy->Houkou == 4) Ptn=0x076B;
sp->X = Enemy->X;
sp->Y = Enemy->Y;
sp->Ptn = Ptn+(Enemy->Cnt/7);
sp->Pri = 3;
sp++;
}
static char
CreateGate(short i,short j)
{
_Gate *Gate;
if ( ((_Gate *)Gate=(_Gate *)malloc(sizeof(_Gate))) == NULL ) return 0;
Gate->Next = GateStart->Next;
Gate->Prev = GateStart;
Gate->Prev->Next = Gate;
Gate->Next->Prev = Gate;
Gate->X = j*16+16+8;
Gate->Y = i*16+16+8;
Gate->Status = 5;
Gate->OpenFlag = 0;
Gate->AnimeCnt = 255;
return -1;
}
static void
Gate(void)
{
_Gate *Gate;
short Ptn;
_Enemy *Enemy,*Dummy;
unsigned int Cnt;
_Sprite *GateSp;
short AddTblX[8] = { 0, 1,2,1,0,-1,-2,-1};
short AddTblY[8] = {-2, -1,0,1,2, 1, 0,-1};
unsigned short StarTbl[4] = {0x034e,0x034f,0x035e,0x035f};
int i;
(_Sprite *)GateSp = &Sprite[127];
Gate = GateStart->Next;
while ( Gate->Next != NULL ) {
if (Gate->AnimeCnt < 32) {
for (i=0;i<8;i++) {
sp->X = Gate->X+(AddTblX[i] * Gate->AnimeCnt);
sp->Y = Gate->Y+(AddTblY[i] * Gate->AnimeCnt);
sp->Ptn = StarTbl[Gate->AnimeCnt/8];
sp->Pri = 3;
sp++;
}
Gate->AnimeCnt ++;
}
/* GateOpen */
if (!Gate->OpenFlag) {
if (Gate->Y == My->Y && (Gate->X < (My->X+16) && My->X < (Gate->X+16))) {
Gate->Status = (Gate->X - My->X)/3;
if (Gate->Status<0) Gate->Status *= -1;
}
if (Gate->X == My->X && (Gate->Y < (My->Y+16) && My->Y < (Gate->Y+16))) {
Gate->Status = (Gate->Y - My->Y)/3;
if (Gate->Status<0) Gate->Status *= -1;
}
if (Gate->X == My->X && Gate->Y == My->Y) {
Gate->OpenFlag = 1;
Se(0);
}
}
if (Gate->OpenFlag == 1) {
if (Gate->X+15 < My->X) Gate->OpenFlag = 2;
if (Gate->X-15 > My->X) Gate->OpenFlag = 2;
if (Gate->Y+15 < My->Y) Gate->OpenFlag = 2;
if (Gate->Y-15 > My->Y) Gate->OpenFlag = 2;
}
if (Gate->OpenFlag == 2) {
if (Gate->Y == My->Y && (Gate->X < (My->X+16) && My->X < (Gate->X+16))) {
Gate->Status = (Gate->X - My->X)/3;
if (Gate->Status<0) Gate->Status *= -1;
Gate->Status = 5 - Gate->Status;
}
if (Gate->X == My->X && (Gate->Y < (My->Y+16) && My->Y < (Gate->Y+16))) {
Gate->Status = (Gate->Y - My->Y)/3;
if (Gate->Status<0) Gate->Status *= -1;
Gate->Status = 5 - Gate->Status;
}
if (Gate->X == My->X && Gate->Y == My->Y) {
Gate->OpenFlag = 3;
Se(1);
}
}
if (Gate->OpenFlag == 3) {
Cnt=1;
Enemy = Start->Next;
while (Enemy->Next != NULL) {
if (Gate->X == Enemy->X && Gate->Y == Enemy->Y && Enemy->DownCnt) {
/* if (!PcmFlag) {
Se(2);
PcmFlag = -1;
}
*/
Dummy = Enemy;
Enemy->Prev->Next = Enemy->Next;
Enemy->Next->Prev = Enemy->Prev;
Enemy = Enemy->Next;
free(Dummy);
Gate->OpenFlag = 4;
EnemyCnt--;
Gate->AnimeCnt = 0;
if (!EnemyCnt) {
Bgm(4);
PcmFlag = -1;
} else {
if (!PcmFlag) {
Se(2);
PcmFlag = -1;
GateCloseCnt ++;
if (GateCloseCnt == 2) TargetTimer=0;
}
}
Score +=(Cnt*100);
StageScore +=(Cnt*100);
Cnt++;
} else {
Enemy = Enemy->Next;
}
}
if (Gate->X+15 < My->X) Gate->OpenFlag = 0;
if (Gate->X-15 > My->X) Gate->OpenFlag = 0;
if (Gate->Y+15 < My->Y) Gate->OpenFlag = 0;
if (Gate->Y-15 > My->Y) Gate->OpenFlag = 0;
}
if (Gate->OpenFlag != 4) {
Ptn = 0x0208-Gate->Status;
} else {
Ptn = 0x0209;
}
GateSp->X = Gate->X;
GateSp->Y = Gate->Y;
GateSp->Ptn = Ptn;
GateSp->Pri = 3;
GateSp--;
Gate = Gate->Next;
}
}
static char
BgmRead(void)
{
FILE *FilePtr;
unsigned char Str[256];
char *From;
char *To;
unsigned char i;
unsigned char j;
char *Addr;
unsigned char BgmCnt=0;
unsigned char BgmFile[128][32];
FilePtr = fopen("Bgm.dat","rt");
if (FilePtr != NULL) {
i=0;
while (!feof(FilePtr)) {
fgets(Str,256,FilePtr); /* 1 line read */
From=strrchr(Str,'<');
To =strrchr(Str,'>');
if (From != NULL && To != NULL) {
j=0;
for (Addr=From+1;Addr<=To-1;Addr++) {
BgmFile[i][j]=*(char *)Addr;
j++;
}
BgmFile[i][j] = 0; /* end code insert */
BgmFile[i][j+1] = 0; /* end code insert */
i++;
BgmCnt++;
}
}
fclose (FilePtr);
} else {
printf("éaéfélÆΦï`üiBgm.Datüjâtâ@âCâïé╠ô╟é▌ì₧é▌é╔Ä╕ösé╡é▄é╡é╜üI\n");
return 0;
}
/* FileLength check */
for (i=0;i<=BgmCnt-1;i++) {
if ((FilePtr = fopen(BgmFile[i],"rb")) != NULL) {
BgmSize[i] = filelength(fileno(FilePtr));
if (((unsigned char *)BgmPtr[i]=(unsigned char *)malloc(BgmSize[i])) == NULL) {
printf("éaéfélâtâ@âCâïüi%süjé╠âüâéâèèmò█é╔Ä╕ösé╡é▄é╡é╜üI\n",BgmFile[i]);
return 0;
} else {
printf("%s é≡ %d éaéÖéöéàô╟é▌ì₧é±é┼é▄é╖üB\n",BgmFile[i],BgmSize[i]);
fread(BgmPtr[i],1,BgmSize[i],FilePtr);
fclose(FilePtr);
}
} else {
printf("éaéfélâtâ@âCâïüi%süjé╠ô╟é▌ì₧é▌é╔Ä╕ösé╡é▄é╡é╜üBBgm.Daté≡Æ▓é╫é─ë║é│éóüI\n",BgmFile[i]);
return 0;
}
}
return -1;
}
static char
Bgm(unsigned char i)
{
/* int hOpm;
unsigned char *FileName = "OPM";
hOpm = OPEN(FileName,0x001);
WRITE(hOpm,BgmPtr[i],BgmSize[i]);
CLOSE(hOpm);
return -1;
*/
BgmStop();
BgmPlay(BgmSize[i],BgmPtr[i]);
return -1;
}
static char
SeRead(void)
{
FILE *FilePtr;
unsigned char Str[256];
char *From;
char *To;
unsigned char i;
unsigned char j;
char *Addr;
unsigned char SeCnt=0;
unsigned char SeFile[128][32];
FilePtr = fopen("Se.dat","rt");
if (FilePtr != NULL) {
i=0;
while (!feof(FilePtr)) {
fgets(Str,256,FilePtr); /* 1 line read */
From=strrchr(Str,'<');
To =strrchr(Str,'>');
if (From != NULL && To != NULL) {
j=0;
for (Addr=From+1;Addr<=To-1;Addr++) {
SeFile[i][j]=*(char *)Addr;
j++;
}
SeFile[i][j] = 0; /* end code insert */
SeFile[i][j+1] = 0; /* end code insert */
i++;
SeCnt++;
}
}
fclose (FilePtr);
} else {
printf("érédÆΦï`üiSe.Datüjâtâ@âCâïé╠ô╟é▌ì₧é▌é╔Ä╕ösé╡é▄é╡é╜üI\n");
return 0;
}
/* FileLength check */
for (i=0;i<=SeCnt-1;i++) {
if ((FilePtr = fopen(SeFile[i],"rb")) != NULL) {
SeSize[i] = filelength(fileno(FilePtr));
if (((unsigned char *)SePtr[i]=(unsigned char *)malloc(SeSize[i])) == NULL) {
printf("érédâtâ@âCâïüi%süjé╠âüâéâèèmò█é╔Ä╕ösé╡é▄é╡é╜üI\n",SeFile[i]);
return 0;
} else {
printf("%s é≡ %d éaéÖéöéàô╟é▌ì₧é±é┼é▄é╖üB\n",SeFile[i],SeSize[i]);
fread(SePtr[i],1,SeSize[i],FilePtr);
fclose(FilePtr);
}
} else {
printf("érédâtâ@âCâïüi%süjé╠ô╟é▌ì₧é▌é╔Ä╕ösé╡é▄é╡é╜üBSe.Daté≡Æ▓é╫é─ë║é│éóüI\n",SeFile[i]);
return 0;
}
}
return -1;
}
static void
Se(unsigned char i)
{
/*
if (ADPCMSNS()==0x02) ADPCMMOD(00);
ADPCMOUT(SePtr[i],0x0403,SeSize[i]);
*/
SePlay(8,(SePtr[i]+10));
}
/* End Program */